﻿using System.Windows.Data;
using Microsoft.Practices.Prism.Regions;
using Tanmia.Basis.Prism;
using Tanmia.Basis.ViewInterface;
using Tanmia.Basis.ViewModel;
using Tanmia.Warehouse.Core;
using Tanmia.Warehouse.Domain;

namespace Tanmia.Warehouse.Presentation.Scenarios
{
    public class SectionViewModel : BaseEditAndBrowseViewModel<Section>
    {
        private Section paramSection;
        private Branch paramBranch;

        public SectionDomain SectionObj { get { return DomainObject as SectionDomain; } }
        public BranchDomain BranchObj { get; private set; }
        public SectionTypeDomain SectionTypeObj { get; private set; }

        public CollectionView Branchs { get; private set; }
        public CollectionView Sections { get; private set; }
        public CollectionView SectionTypes { get; private set; }

        public SectionViewModel(IShellView shellView, IRegionManager regionManager, IMessageService messageService, SectionDomain sectionDmn, BranchDomain branchDmn, SectionTypeDomain sectionTypeDmn)
            : base(shellView, regionManager, messageService, sectionDmn)
        {
            this.BranchObj = branchDmn;
            this.SectionTypeObj = sectionTypeDmn;
            Branchs = new CollectionView(BranchObj.Gets());
            Sections = new CollectionView(SectionObj.GetsWithHead());
            SectionTypes = new CollectionView(SectionTypeObj.Gets());
        }

        public override void OnNavigatedTo(NavigationContext navigationContext)
        {
            paramBranch = navigationContext.GetParameter<Branch>("selectedTreeNode");
            paramSection = navigationContext.GetParameter<Section>("selectedTreeNode");

            Branchs.MoveCurrentTo(paramBranch);
            Sections.MoveCurrentTo(paramSection);
        }
    }
}
